home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tests / fmath.test < prev    next >
Encoding:
Text File  |  1992-11-09  |  6.8 KB  |  247 lines

  1. #
  2. # fmath.test
  3. #
  4. # Tests for the following floating point math commands:
  5. #   acos, asin, atan,  cos,  sin,  tan,   cosh, sinh, tanh, 
  6. #   exp,  log,  log10, sqrt, fabs, floor, ceil, fmod, pow.
  7. #---------------------------------------------------------------------------
  8. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  9. #
  10. # Permission to use, copy, modify, and distribute this software and its
  11. # documentation for any purpose and without fee is hereby granted, provided
  12. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  13. # Mark Diekhans make no representations about the suitability of this
  14. # software for any purpose.  It is provided "as is" without express or
  15. # implied warranty.
  16. #------------------------------------------------------------------------------
  17. # $Id: fmath.test,v 2.1 1992/11/09 07:33:02 markd Exp $
  18. #------------------------------------------------------------------------------
  19. #
  20.  
  21. if {[info procs test] != "test"} then {source testlib.tcl}
  22.  
  23. set F_E            2.71828
  24. set F_LN10    2.30258
  25. set F_PI    3.14159265358979
  26. set F_PI_180    0.0174533
  27. set F_PI_4      0.785398
  28. set F_PI_2      1.5708
  29. set F_SQRT2    1.41421
  30.  
  31. # Check that a floating point value is reasonably within range.  If so, return
  32. # 1, if not, return a message.
  33.  
  34. proc fchecknum {got expect} {
  35.     global ModuleName
  36.  
  37.     set lowExpect [expr {$expect * 0.9999}]
  38.     set hiExpect  [expr {$expect * 1.0001}]
  39.  
  40.     if {($got < $lowExpect) || ($got > $hiExpect)} {
  41.       return [format {wanted something close to %s, got %s} $expect $got]
  42.     }
  43.     return 1
  44. }
  45.  
  46. test fmath-1.1 {acos tests} {
  47.     list [catch acos msg] $msg
  48. } {1 {wrong # args: acos expr}}
  49. test fmath-1.2 {acos tests} {
  50.     list [catch {acos 1 1} msg] $msg
  51. } {1 {wrong # args: acos expr}}
  52. test fmath-1.3 {acos tests} {
  53.     fchecknum [acos 0] 1.5708
  54. } 1
  55. test fmath-1.4 {acos tests} {
  56.     fchecknum [acos $F_PI_180-.5] 2.07436
  57. } 1
  58. test fmath-1.5 {acos tests} {
  59.     fchecknum [acos $F_PI_4] 0.667457
  60. } 1
  61. test fmath-1.6 {acos tests} {
  62.     fchecknum [acos .25*.25] 1.50826
  63. } 1
  64.  
  65.  
  66. test fmath-2.1 {asin tests} {
  67.     list [catch {asin} msg] $msg
  68. } {1 {wrong # args: asin expr}}
  69. test fmath-2.2 {asin tests} {
  70.     list [catch {asin 1 1} msg] $msg
  71. } {1 {wrong # args: asin expr}}
  72. test fmath-2.3 {asin tests} {
  73.     fchecknum [asin 1.3-.4] 1.11977
  74. } 1
  75.  
  76. test fmath-3.1 {atan tests} {
  77.     list [catch {atan} msg] $msg
  78. } {1 {wrong # args: atan expr}}
  79. test fmath-3.2 {atan tests} {
  80.     list [catch {atan 1 1} msg] $msg
  81. } {1 {wrong # args: atan expr}}
  82. test fmath-3.3 {atan tests} {
  83.     fchecknum [atan 1.0-.25] 0.643501
  84. } 1
  85.  
  86. test fmath-4.1 {cos tests} {
  87.     list [catch {cos} msg] $msg
  88. } {1 {wrong # args: cos expr}}
  89. test fmath-4.1 {cos tests} {
  90.     list [catch {cos 1 1} msg] $msg
  91. } {1 {wrong # args: cos expr}}
  92.  
  93. test fmath-5.1 {sin tests} {
  94.     list [catch {sin} msg] $msg
  95. } {1 {wrong # args: sin expr}}
  96. test fmath-5.2 {sin tests} {
  97.     list [catch {sin 1 1} msg] $msg
  98. } {1 {wrong # args: sin expr}}
  99. test fmath-5.3 {sin tests} {
  100.     fchecknum [sin 1.0-.1] 0.783327
  101. } 1
  102.  
  103. test fmath-6.1 {tan tests} {
  104.     list [catch {tan} msg] $msg
  105. } {1 {wrong # args: tan expr}}
  106. test fmath-6.2 {tan tests} {
  107.     list [catch {tan 1 1} msg] $msg
  108. } {1 {wrong # args: tan expr}}
  109. test fmath-6.3 {tan tests} {
  110.     fchecknum [tan .01*10] 0.100335
  111. } 1
  112.  
  113. test fmath-7.1 {cosh tests} {
  114.     list [catch {cosh} msg] $msg
  115. } {1 {wrong # args: cosh expr}}
  116. test fmath-7.2 {cosh tests} {
  117.     list [catch {cosh 1 1} msg] $msg
  118. } {1 {wrong # args: cosh expr}}
  119. test fmath-7.3 {cosh tests} {
  120.     fchecknum [cosh 1.2] 1.81066
  121. } 1
  122.  
  123. test fmath-8.1 {sinh tests} {
  124.     list [catch {sinh} msg] $msg
  125. } {1 {wrong # args: sinh expr}}
  126. test fmath-8.2 {sinh tests} {
  127.     list [catch {sinh 1 1} msg] $msg
  128. } {1 {wrong # args: sinh expr}}
  129. test fmath-8.3 {sinh tests} {
  130.     fchecknum [sinh .25+10] 14141.3
  131. } 1
  132.  
  133. test fmath-9.1 {tanh tests} {
  134.     list [catch {tanh} msg] $msg
  135. } {1 {wrong # args: tanh expr}}
  136. test fmath-9.2 {tanh tests} {
  137.     list [catch {tanh 1 1} msg] $msg
  138. } {1 {wrong # args: tanh expr}}
  139. test fmath-9.3 {tanh tests} {
  140.     fchecknum [tanh 1.5/2] 0.635149
  141. } 1
  142.  
  143. test fmath-10.1 {exp tests} {
  144.     list [catch {exp} msg] $msg
  145. } {1 {wrong # args: exp expr}}
  146. test fmath-10.2 {exp tests} {
  147.     list [catch {exp 1 1} msg] $msg
  148. } {1 {wrong # args: exp expr}}
  149. test fmath-10.3 {exp tests} {
  150.     fchecknum [exp 1.4] 4.0552
  151. } 1
  152.  
  153. test fmath-11.1 {log tests} {
  154.     list [catch {log} msg] $msg
  155. } {1 {wrong # args: log expr}}
  156. test fmath-11.2 {log tests} {
  157.     list [catch {log 1 1} msg] $msg
  158. } {1 {wrong # args: log expr}}
  159. test fmath-11.3 {log tests} {
  160.     fchecknum [log (110%3)*8] 2.77259
  161. } 1
  162.  
  163. test fmath-12.1 {log10 tests} {
  164.     list [catch {log10} msg] $msg
  165. } {1 {wrong # args: log10 expr}}
  166. test fmath-12.2 {log10 tests} {
  167.     list [catch {log10 1 1} msg] $msg
  168. } {1 {wrong # args: log10 expr}}
  169. test fmath-12.3 {log10 tests} {
  170.     fchecknum [log10 0.5*10] 0.69897
  171. } 1
  172.  
  173. test fmath-13.1 {sqrt tests} {
  174.     list [catch {sqrt} msg] $msg
  175. } {1 {wrong # args: sqrt expr}}
  176. test fmath-13.2 {sqrt tests} {
  177.     list [catch {sqrt 1 1} msg] $msg
  178. } {1 {wrong # args: sqrt expr}}
  179. test fmath-13.3 {sqrt tests} {
  180.     fchecknum [sqrt 1.2*2] 1.54919
  181. } 1
  182.  
  183. test fmath-14.1 {fabs tests} {
  184.     list [catch {fabs} msg] $msg
  185. } {1 {wrong # args: fabs expr}}
  186. test fmath-14.2 {fabs tests} {
  187.     list [catch {fabs 1 1} msg] $msg
  188. } {1 {wrong # args: fabs expr}}
  189. test fmath-14.3 {fabs tests} {
  190.     fchecknum [fabs 1.2-10.5] 9.3
  191. } 1
  192.  
  193. test fmath-15.1 {floor tests} {
  194.     list [catch {floor} msg] $msg
  195. } {1 {wrong # args: floor expr}}
  196. test fmath-15.2 {floor tests} {
  197.     list [catch {floor 1 1} msg] $msg
  198. } {1 {wrong # args: floor expr}}
  199. test fmath-15.3 {floor tests} {
  200.     fchecknum [floor 1.2*10.3] 12
  201. } 1
  202.  
  203. test fmath-16.1 {ceil tests} {
  204.     list [catch {ceil} msg] $msg
  205. } {1 {wrong # args: ceil expr}}
  206. test fmath-16.2 {ceil tests} {
  207.     list [catch {ceil 1 1} msg] $msg
  208. } {1 {wrong # args: ceil expr}}
  209. test fmath-16.3 {ceil tests} {
  210.     fchecknum [ceil 1.5*2.6] 4
  211. } 1
  212.  
  213. test fmath-17.1 {fmod tests} {
  214.     list [catch {fmod} msg] $msg
  215. } {1 {wrong # args: fmod expr divisor}}
  216. test fmath-17.2 {fmod tests} {
  217.     list [catch {fmod 1 1 1} msg] $msg
  218. } {1 {wrong # args: fmod expr divisor}}
  219. test fmath-17.3 {fmod tests} {
  220.     list [catch {fmod 1 1 1} msg] $msg
  221. } {1 {wrong # args: fmod expr divisor}}
  222. test fmath-17.4 {fmod tests} {
  223.     fchecknum [fmod 1.2*3 1.0/.25] 3.6
  224. } 1
  225.  
  226. test fmath-18.1 {pow tests} {
  227.     list [catch {pow} msg] $msg
  228. } {1 {wrong # args: pow expr exp}}
  229. test fmath-18.2 {pow tests} {
  230.     list [catch {pow 1 1 1} msg] $msg
  231. } {1 {wrong # args: pow expr exp}}
  232. test fmath-18.3 {pow tests} {
  233.     fchecknum [pow 13.6*.78 1.2] 17.0122
  234. } 1
  235.  
  236. test fmath-19.1 {math error tests} {
  237.     list [catch {sqrt -1} msg] $msg
  238. } {1 {floating point domain error}}
  239. test fmath-19.2 {math error tests} {
  240.     list [catch {acos 1000} msg] $msg
  241. } {1 {floating point domain error}}
  242. test fmath-19.3 {math error tests} {
  243.     list [catch {pow 10000 100000} msg] $msg
  244. } {1 {floating point overflow error}}
  245.  
  246.  
  247.